﻿//创建时间: 2010-10-11
//创建作者: 李 城
//功能说明: 可选值管理 列表显示
//最后修改: 2010-10-11
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CMS.Web.UI;


using TRPOP.CMS.Business;
using TRPOP.CMS.Model;

namespace TRPOP.CMS.Web.Admin
{
    public partial class FormInputValueType_list : BaseAdmin
    {

        #region 当前页面权限验证
        protected override void SubPageInit()
        {
            base.m_SubPagePermission = Plugin.PermissionKeys.PermissionEnum.SystemManage_ContentModel;
        }
        #endregion

        #region 页面变量
        protected string m_strTitle = "所有可选值";
        protected string m_initSelect = "=====请选择类型=====";
        protected string m_straddinfo = "";
        protected string m_strFormInputValueType = "";
        protected FormInputValueTypeManage m_FormInputValueTypeManage = new FormInputValueTypeManage();
        protected FormInputValueManage m_FormInputValueManage = new FormInputValueManage();
        protected List<FormInputValueInfoWithLevel> m_listInfo = new List<FormInputValueInfoWithLevel>();
        protected FormInputValueTypeInfo m_FormInputValueTypeInfo = new FormInputValueTypeInfo();
        #endregion

        #region 页面事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadBase();
                LoadData(ddlFormInputValueType.SelectedIndex, ddlFormInputValue.SelectedIndex, false);
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {

        }
        protected void lbtnDelete_Click(object sender, EventArgs e)
        {
            LinkButton lbtn = (LinkButton)sender;
            int intFormInputLimitTypeId = 0;
            int.TryParse(lbtn.CommandArgument, out intFormInputLimitTypeId);
            InitPageViewState("typeIndex", ddlFormInputValueType.SelectedIndex);
            InitPageViewState("ValueIndex", ddlFormInputValue.SelectedIndex);
            SubmitAlertDelete(m_FormInputValueManage.DeleteInfoById(intFormInputLimitTypeId));
            LoadData(GetPageViewState("typeIndex").ToString().ToInt(), GetPageViewState("ValueIndex").ToString().ToInt(), false);
        }

        protected void ddlFormInputValueType_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadData(0, 0, true);
        }

        #endregion

        #region 页面方法

        public void LoadBase()
        {
            ddlFormInputValueType.DataSource = m_FormInputValueTypeManage.GetListByCondition(0, "", " FormInputValueTypeId asc");
            ddlFormInputValueType.DataTextField = "Name";
            ddlFormInputValueType.DataValueField = "FormInputValueTypeId";
            ddlFormInputValueType.DataBind();
            ddlFormInputValueType.Items.Insert(0, new ListItem(m_initSelect, "0"));
            if (RequestHelper.RequestInt("cid") > 0)
                ddlFormInputValueType.SelectedValue = RequestHelper.RequestString("cid");
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="typeIndex">可选值类型 所选的index</param>
        /// <param name="ValueIndex">可选值 所选的index</param>
        /// <param name="isTypeChangeg">可选值类型是否重新选择</param>
        public void LoadData(int typeIndex, int ValueIndex, bool isTypeChangeg)
        {
            //如果没有重新选择可选值类型
            if (!isTypeChangeg)
                ddlFormInputValueType.SelectedIndex = typeIndex;
            //加载可选值
            if (ddlFormInputValueType.SelectedIndex <= 0)
            {
                ddlFormInputValue.Items.Clear();
                ddlFormInputValue.Items.Insert(0, new ListItem(m_initSelect, "-1"));
                rptList.DataSource = null;
                rptList.DataBind();
            }
            else
            {
                //获取可选值类型下的所有可选值
                m_FormInputValueTypeInfo = m_FormInputValueTypeManage.GetInfoById(ddlFormInputValueType.SelectedValue.ToInt());
                m_strTitle = m_FormInputValueTypeInfo.Name;
                m_straddinfo = "(级数:" + m_FormInputValueTypeInfo.Step.ToString() + " )";
                m_listInfo = m_FormInputValueManage.GetFormInputValueListTree(m_FormInputValueTypeInfo.FormInputValueTypeId, 0, -1, "");
                foreach (FormInputValueInfoWithLevel oinfo in m_listInfo)
                {
                    oinfo.Name = PageAssist.AppendStr(oinfo.Level, "——") + oinfo.Name;
                }
                //绑定dropdownlist
                ddlFormInputValue.DataSource = m_listInfo;
                ddlFormInputValue.DataTextField = "Name";
                ddlFormInputValue.DataValueField = "FormInputValueId";
                ddlFormInputValue.DataBind();
                ddlFormInputValue.Items.Insert(0, new ListItem("====" + ddlFormInputValueType.SelectedItem.Text + "====", "0"));
                //选择可选值
                ddlFormInputValue.SelectedIndex = ValueIndex;
                //绑定rptlist
                rptList.DataSource = m_listInfo;
                rptList.DataBind();
            }
        }

        public void LoadPostBacrData()
        {
            ddlFormInputValue.Items.Clear();
            if (ddlFormInputValueType.SelectedIndex <= 0)
            {
                ddlFormInputValue.Items.Insert(0, new ListItem(m_initSelect, "-1"));
                rptList.DataSource = null;
                rptList.DataBind();
                return;
            }
            else
            {
                m_FormInputValueTypeInfo = m_FormInputValueTypeManage.GetInfoById(ddlFormInputValueType.SelectedValue.ToInt());
                if (m_FormInputValueTypeInfo == null)
                    return;
                m_strTitle = m_FormInputValueTypeInfo.Name;
                m_straddinfo = "(级数:" + m_FormInputValueTypeInfo.Step.ToString() + " )";

                m_listInfo = m_FormInputValueManage.GetFormInputValueListTree(m_FormInputValueTypeInfo.FormInputValueTypeId, 0, -1, "");
                foreach (FormInputValueInfoWithLevel oinfo in m_listInfo)
                {
                    oinfo.Name = PageAssist.AppendStr(oinfo.Level, "——") + oinfo.Name ;
                }
                InitPageViewState("modellist", m_listInfo);
            }
            ddlFormInputValue.DataSource = (List<FormInputValueInfoWithLevel>)GetPageViewState("modellist");
            ddlFormInputValue.DataTextField = "Name";
            ddlFormInputValue.DataValueField = "FormInputValueId";
            ddlFormInputValue.DataBind();
            ddlFormInputValue.Items.Insert(0, new ListItem("====" + ddlFormInputValueType.SelectedItem.Text + "====", "0"));
            rptList.DataSource = (List<FormInputValueInfoWithLevel>)GetPageViewState("modellist");
            rptList.DataBind();
        }
        #endregion
    }
}
